object ForComprehensionDemo extends App {
  val rawScore: List[Double] = List(75.0, 82.5, 90.0, 68.0, 85.5, 79.0, 92.0)

  val standardScore = for (score <- rawScore) yield score * 0.8 +20
  println(s"原始分数：$rawScore")
  println(s"标准分数：$standardScore")

  val excellentScores = for {
    score <- standardScore
    if score >= 80
  } yield score
  println(s"优秀标准分（>=80）：$excellentScores")

  val scoreDetails = for {
    raw <- rawScore
    standard = raw * 0.8 + 20
  } yield (raw, standard, if (standard >= 80) "达标" else "未达标")

  println("\n成绩详情：")
  scoreDetails.foreach { case (raw, std, status) =>
    println(f"原始分：$raw%.1f -> 标准分：$std%.1f （$status）")
  }

  val avgExcellent = if (excellentScores.nonEmpty) {
    excellentScores.sum / excellentScores.length
  } else 0.0
  println(f"\n优秀学生标准分平均分：$avgExcellent%.1f")
}
//第九周(动手练习 4：转换成绩数据并生成统计信息）